class Solution
{
public:
    vector<int> mostCompetitive(vector<int> &nums, int k)
    {
        vector<int> s;
        int n = nums.size();
        int last = n - k;
        for (int i = 0; i < n; i++)
        {
            while (!s.empty() && last > 0 && s.back() > nums[i])
            {
                s.pop_back();
                last--;
            }
            s.push_back(nums[i]);
        }
        for (int i = 0; i < last; i++)
        {
            s.pop_back();
        }
        return s;
    }
};
